<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>用户登录</title>
</head>
<body>
<form id="signInForm" action="">
    <div>
        <label>用户名:<input type="text" name="name"></label>
    </div>
    <div>
        <label>密  码:<input type="password" name="password"></label>
    </div>
    <div>
        <button type="submit">登录</button>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        const $signInForm = $('#signInForm');
        $signInForm.on('submit',(e)=>{
            e.preventDefault();
            const name = $signInForm.find('input[name=name]').val();
            const password = $signInForm.find('input[name=password]').val();
            console.log(name,password)
            $.ajax({
                url:'/sign_in',
                data:JSON.stringify({name,password}),
                method:'post',
                contentType:'text/json; charset=UTF-8;'
            }).then(()=>{
                alert('登录成功!')
                location.href = './home.html'
            },()=>{})
        })

    </script>
</form>
</body>
</html>